﻿using UnityEngine;

public abstract class LevelCompAbs : MonoBehaviour
{
    // 当前经验
    public float experience = 0;

    // 当前等级
    public int level = 1;


    public void AddExperience(float value)
    {
        experience = experience + value;
        while (experience >= GetExperienceToLevelUp())
        {
            var oldValues = this.level;
            level = level + 1;
            RxEventBus.Publish(new LevelChangeEvent(oldValues, this.level));
        }
    }

    /**
     * 根据等级计算下一个升级所需的经验
     * 可以结合数据表或者算法进行计算
     */
    protected abstract float GetExperienceToLevelUp();
}